.386
.model flat,stdcall
option casemap:none
include\masm32\include\windows.inc
include\masm32\include\kernel32.inc
include\masm32\include\masm32.inc
includelib\masm32\lib\kernel32.lib
includelib\masm32\lib\masm32.lib

.data
num1 dword 11 DUP(0);存放字符串对应数值
array byte 50 DUP(0);存放输入的数据字符串，用空格隔开
str_start byte"please input 10 numbers:",0
outans db 50 DUP(0) ;输出字符串
out_str_r db 50 DUP(0) ;反序储存的字符串
reminder DWORD 0
weight DWORD 10;被除数
cnt DWORD 0
Count DWORD ?


.code
start:
    invoke StdOut,addr str_start
    invoke StdIn,addr array ,50
    mov esi,0h
    mov eax,0h;索引

input_num:
    mov ebx,0h;每次把一个数字变成字符
    mov edx,0h; 储存每次的结果

transform:
    mov bl,byte ptr array[eax]
    cmp bl,20h;判断该位上是否为空格
    je store
    sub bl,30h;将字符转换成数字

    mov ecx,edx
    shl edx,3
    shl ecx,1
    add edx,ecx
    add edx,ebx;不断乘10相加得到对应数值

    inc eax
    jmp transform

store:
    mov dword ptr num1[esi] ,edx;此时edx储存第一个数字
    inc eax
    add esi,4
    cmp esi,40;判断是否存满十个数据
    jb input_num

readysort:
    mov Count,0ah
    mov esi,offset num1

Bubblesort:
    mov esi,36
outsidecircle:;外层循环

    mov edi,0
    insidecircle:;内层循环
    mov eax,dword ptr num1[edi]
    mov ebx,dword ptr num1[edi+4]

    cmp eax,ebx
    jg noexchange;不需要排序的情况
    mov dword ptr num1[edi+4],eax
    mov dword ptr num1[edi],ebx

noexchange:
    add edi,4
    cmp edi,esi
    jne  insidecircle

    sub esi,4
    mov eax,esi
    mov ebx,0
    cmp eax,ebx
    je circleover
    jmp outsidecircle

circleover:

data_to_str:
    mov esi,offset num1
    mov edi,offset outans
	mov cnt,0  ;记录处理个数
	mov Count,0  ;记录十进制字符串ASCII码位置
	mov ecx,10
	mov edx,0
L4:
	mov ebx,cnt
	inc cnt
	mov eax,[esi+ebx*4]

get_d:
	mov edx,0	;清0
	div weight
	add edx,30h  ;将数据转换成字符
	mov reminder,eax	;保存商
	mov eax,Count
	mov out_str_r[eax],dl	;放一个数位进去
	inc Count

	mov eax,reminder	;再返回商
	cmp reminder,0
	JNE get_d	;不为0继续除

	mov eax,Count
	mov out_str_r[eax],' '	;为零代表做完一个数了
	inc Count
	loop L4


	mov ecx,Count
	mov ebx,0

L5:
	;将字符串反转过来
	mov al,[out_str_r+ecx-1]
	mov [edi+ebx],al
	inc ebx
	loop L5
	mov eax,0
	mov [edi+ebx],eax

    invoke StdOut,addr outans
    invoke ExitProcess,0
END start